package com.atm.service.impl;

import com.atm.dao.UserDao;
import com.atm.pojo.RunMessage;
import com.atm.pojo.User;
import com.atm.service.UserService;

import java.util.List;

public class UserServiceImpl implements UserService {
    private final UserDao userDao=new UserDao();
    @Override
    public List<User> findAllUsers() {
        return userDao.findAllUsers();
    }

    @Override
    public List<User> queryUsers(String name) {
        return userDao.queryUsers(name);
    }

    @Override
    public User getUserByIcno(String icno) {
        return userDao.getUserByIcno(icno);
    }

    @Override
    public boolean updateUser(User user) {
        return userDao.updateUser(user)>=1?true:false;
    }

    @Override
    public boolean deleteUser(String icno) {
        return userDao.deleteUser(icno)>=1?true:false;
    }

    @Override
    public boolean addUser(User user) {
        return userDao.addUser(user) >= 1;
    }

    @Override
    public User findUserByNameAndPwd(String icno, String pwd) {
        return userDao.findUserByNameAndPwd(icno, pwd);
    }

    @Override
    public boolean updateUserPwd(String icno,String newpwd) {
        return userDao.updateUserPwd(icno, newpwd) >= 1;
    }

    @Override
    public double getUserBalance(String icno) {
        return userDao.getUserBalance(icno);
    }

    @Override
    public boolean saveMoney(int money,String icno) {
        return userDao.saveMoney(money,icno) >= 1;
    }

    @Override
    public boolean FetchMoney(int money, String icno) {
        return userDao.fetchMoney(money,icno) >=1;
    }

    @Override
    public boolean transfer(String transferIn, String icno, int money) {
        //转入
        int i = userDao.saveMoney(money, transferIn);
        if (i >= 1) {
            //转出
            int i1 = userDao.fetchMoney(money, icno);
            if (i1 >= 1){
                return true;
            }
        }
        return false;
    }

    /**
     * 获取email
     *
     * @param icno 卡号
     * @return 邮箱地址
     */
    @Override
    public String getEmailByIcno(String icno) {
        return userDao.getEmailByIcno(icno);
    }


}
